import java.util.Scanner;
public class problem02 {
    public static void main(String[] args) {
        System.out.println("请输入数组的大小");
        Scanner sc=new Scanner(System.in);
        int size=sc.nextInt();
        System.out.println("请输入数组的元素");
        int[] arr=new int[size];
        for(int m=0;m<size;m++){
            arr[m]=sc.nextInt();
        }
        int i=0,j=0,count=0;
        for(i=0;i<arr.length;) {
            if(i==arr.length-1){
                if(arr[i]>0){
                    count+=arr[i];
                    break;
                }else{
                    break;
                }
            }
            if(i==j){
                if(arr[i]>0){
                    count+=arr[i];
                    i++;
                }else{
                    i++;
                }
            }else{
                if(arr[i]>=0) {
                    count+=arr[i];
                    i++;
                    j++;
                }else{
                    if(arr[i]+arr[j]<0){
                        count-=arr[j];
                        i++;
                        j++;
                    }else{
                        count+=arr[i];
                        i++;
                        j++;
                    }
                }
            }
        }
        System.out.println(count);
    }
}
